# 初始化
set1=set()# 空集合只能用set()初始化 不能用{}

l1=[1,1,1,1,2,3,3,3,3]
set2=set(l1)
print(set2) #1, 2, 3


set1={1,2}
set1.add(3)
print(set1) #1, 2, 3


set1={1,2,3}
tup1=(3,4,5)
set1.update(tup1)
print(set1) #1, 2, 3, 4, 5



set1={1,2,3}
set1.remove(1)
print(set1) #{2, 3} 不存在会报错


set1={1,2,3}
set1.clear()
print(set1)


set1={1,2,3}
set1.discard(1)
print(set1)#元素不在不会报错

# 判断相等
set1={1,2,3,4}
set2={1,2,3,4}
print(set1==set2) #true


# 差集
set1={1,2,3}
set2={1,2}
set3=set1-set2
print(set3) #{3}


# 交集
set1={1,2,3}
set2={1,2}
set3=set1&set2
print(set3) #{1, 2}


# 并集
set1={1,2,3}
set2={1,2}
set3=set1 | set2
print(set3) #1, 2, 3

# 对称差集
set1={1,2,3,4,5}
set2={4,5,6,7}
set3=set1^set2
print(set3) #{1, 2, 3, 6, 7}


